using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections.Specialized;
using PSE.Framework.ErrorLogging;
using PSE.Framework.Configuration;

namespace PSE.Hosting.ServiceHoster.Logging
{
    public class Logger
    {
        public enum EntryType
        {
            Information = 0,
            Warning = 1,
            Error = 2
        }

        public static void Log(string message, EntryType entryType)
        {
            Log(ApplicationConfiguration.CurrentSystem, ApplicationConfiguration.CurrentComponent, message, entryType);
        }

        public static void Log(SystemComponent system, SystemComponent component, object message, EntryType entryType)
        {
            LogType logType;

            switch (entryType)
            {
                case EntryType.Information:
                    logType = LogType.Information;
                    break;

                case EntryType.Warning:
                    logType = LogType.Warning;
                    break;

                case EntryType.Error:
                    logType = LogType.Error;
                    break;

                default:
                    logType = LogType.Error;
                    break;
            }

            if (message is Exception)
            {
                ErrorLogger.WriteLog(system, component, logType, (Exception)message);
            }
            else
            {
                ErrorLogger.WriteLog(system, component, logType, message.ToString());
            }
        }

        public static void Log(Exception exception, EntryType entryType)
        {
            Log(ApplicationConfiguration.CurrentSystem, ApplicationConfiguration.CurrentComponent, exception, entryType);
        }
    }
}
